﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SolutionBLL;
using SolutionModel;
using SFast;

public partial class admin_system_MenuInRole : System.Web.UI.Page
{
    T_MenuInRoleBLL mirbll = new T_MenuInRoleBLL();
    T_MenuBLL menuBLL = new T_MenuBLL();

    protected void Page_Load(object sender, EventArgs e)
    {
        this.rp_list.DataSource = menuBLL.GetTree();
        this.rp_list.DataBind();
        mirbll.GetMuneInRoleID("");
    }

    // 提交保存事件
    public void submitSave()
    {
        String roleId = Request.QueryString["id"];
        String menuIds = Request.Form["row_box"];
        if (!roleId._HasVal())
        {
            throw new Exception("无参数:id ");
        }
        List<int> list_menuIds = new List<int>();
        if (menuIds._HasVal())
        {
            menuIds.Split(',').ForEach(o =>
            {
                list_menuIds.Add(Convert.ToInt32(o));
            });
        }
                
        //保存信息
        mirbll.InsertOrUpdate(roleId, list_menuIds);

        MyJs.Alert("保存成功！", "/admin/system/RolesList.aspx");
        
    }


    public void getMenuByRoled()
    {
        String id = Request.QueryString["id"];
        if (!id._HasVal())
        {
            throw new Exception("url中未找到参数{ id }");
        }

        List<String> list_id = new List<string>();
        //遍历集合，只拿到ID返回给浏览器
        mirbll.GetMuneInRoleID(id).ForEach(o => {
            list_id.Add(o.MenuID.ToString());
        });
        Response._WriteEnd(list_id._ToCSV(","));

    }
}